package wireless.association.action;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import wireless.preamble.pojo.Preamble;

import cm.util.hibernate.HibernateSessionFactory;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class AssociationDetail extends ActionSupport {
	
	private String value;
	private String table;
	private Session session;
	private Transaction trans;
    private String hql;
    private Query query;
    

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getTable() {
		return table;
	}

	public void setTable(String table) {
		this.table = table;
	}

	public Session getSession() {
		return session;
	}

	public void setSession(Session session) {
		this.session = session;
	}

	public Transaction getTrans() {
		return trans;
	}

	public void setTrans(Transaction trans) {
		this.trans = trans;
	}

	public String getHql() {
		return hql;
	}

	public void setHql(String hql) {
		this.hql = hql;
	}

	public Query getQuery() {
		return query;
	}

	public void setQuery(Query query) {
		this.query = query;
	}

	public String execute() throws Exception
	{
		value = getValue();
		table = getTable();
		session=HibernateSessionFactory.getSession();
		trans=session.beginTransaction();
		hql="from "+table+" as p where p.value="+value;
		query=session.createQuery(hql);
		List<Preamble> list = query.list();
		ActionContext.getContext().getSession().put("detail",list);
		session.close();
		if(list.isEmpty())
		{
			return "failed";
		}
		return "success";
	}
}
